import { SharedEntity } from 'src/api/shared/entities/shared.entity';
import { UserEntity } from 'src/api/user/entities/user.entity';
import { Column, Entity, JoinColumn, ManyToOne } from 'typeorm';
import { CommentEntity } from './comment.entity';

@Entity('comment_like')
export class CommentLikeEntity extends SharedEntity {
  // 用户id
  @Column('varchar', { name: 'user_id', length: 36 })
  userId: string;

  @ManyToOne(() => UserEntity, (user) => user.articleCommentLikes, {
    onDelete: 'RESTRICT',
    onUpdate: 'RESTRICT',
  })
  @JoinColumn([{ name: 'user_id', referencedColumnName: 'id' }])
  user: UserEntity;

  // 点赞对应的id
  @Column('varchar', { name: 'comment_id', length: 36, comment: '评论id' })
  commentId: string;

  @ManyToOne(() => CommentEntity, (articleComment) => articleComment.likes, {
    onDelete: 'RESTRICT',
    onUpdate: 'RESTRICT',
  })
  @JoinColumn([{ name: 'comment_id', referencedColumnName: 'id' }])
  comment: CommentEntity;
}
